package banking;

public class Account {
    private double balance = 0.0; // 显式初始化余额

    public Account(double bal) {
        // 对初始余额做合法性校验（可选）
        if (bal >= 0) {
            balance = bal;
        } else {
            balance = 0.0;
        }
    }

    public double getBalance() {
        return balance;
    }

    public boolean deposit(double amount) {
        if (amount > 0) { // 存款金额必须为正
            balance += amount;
            return true;
        }
        return false;
    }

    public boolean withdraw(double amount) {
        boolean result = true;
        if (balance < amount || amount <= 0) { // 取款金额不能超过余额，且必须为正
            result = false;
        } else {
            balance -= amount;
        }
        return result;
    }
}

